package model.entity;

import game_engine.GameEngine;
import game_engine.core.Entity;
import game_engine.display.GEUtil;
import game_engine.display.Texture;
import game_engine.display.TextureLoader;

import java.awt.Color;
import java.io.IOException;

public class Bullet extends Entity {

	private static int count = 0;
	private int damage = 5;
	private Entity originator;

	public static final int FRAME_MOVE = 0;
	
	private static final Color transColor = new Color(0xbfdcbf);

	public Bullet(Entity originator) {
		super("bullet" + count++);

		Texture[][] frames = new Texture[1][];
		GameEngine ge = GameEngine.getInstance();
			Texture[] move = new Texture[] { ge.getTexture("images/bullets/fire_bullet1.png", transColor),
					ge.getTexture("images/bullets/fire_bullet2.png", transColor), ge.getTexture("images/bullets/fire_bullet3.png", transColor),
					ge.getTexture("images/bullets/fire_bullet4.png", transColor) };

			frames[0] = move;

		int[][] framesCountList = new int[1][];
		int[] framesCount1 = new int[] { 100, 100, 100, 100 };
		framesCountList[0] = framesCount1;
	
		boolean[] frameLoop = new boolean[1];
		frameLoop[0]  = true;
		currentFrame = 0;
		currentAction = FRAME_MOVE;

		this.setFrames(frames);
		this.setFrameCount(framesCountList);
		this.setFrameLoop(frameLoop);
		
		this.originator = originator;
	}

	@Override
	public void render() {
		if (position != null) {
			GEUtil.drawImage(frames[currentAction][currentFrame], Math.round(position.x),  Math.round(position.y), 10, 10, 255);
		}
	}

	@Override
	public void move(long tick) {
		super.move(tick);
		if (position.x > GameEngine.resolution.width)
			dead = true;
		if (position.x < 0)
			dead = true;
		if (position.y > GameEngine.resolution.height)
			dead = true;
		if (position.y < 0)
			dead = true;
	}

	public void setDamage(int damage) {
		this.damage = damage;
	}

	public int getDamage() {
		return damage;
	}

	@Override
	public void collided(Entity e) {
		if(!e.isUnspawning()) {
			dead = true;
			if(e instanceof Enemy)originator.setValue(originator.getValue() + e.getValue());
		}
	}

	@Override
	public void doAction(float tick) {

	}
}
